package com.ming.yourdiary.entity;

import com.ming.yourdiary.common.DateConstants;

import java.util.Date;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;

public class DiaryNote {

  public int id;
  public DateTime createDate;
  public int weatherCode;
  public String title;
  public String content;

  public DiaryNote(int id, DateTime createDate, int weatherCode, String title, String content) {
    this.id = id;
    this.createDate = createDate;
    this.weatherCode = weatherCode;
    this.content = content;
    this.title = title;
  }

  public DiaryNote(Date createDate, int weatherCode, String title, String content) {
    this.createDate = new DateTime(createDate);
    this.weatherCode = weatherCode;
    this.content = content;
    this.title = title;
  }

  public DiaryNote(String createDate, int weatherCode, String title, String content) {
    this.createDate = new DateTime(createDate, DatePattern.NORM_DATETIME_PATTERN);
    this.weatherCode = weatherCode;
    this.content = content;
    this.title = title;
  }

  //若创建时未传递时间参数，则默认为当前时间
  public DiaryNote(int weatherCode, String title, String content) {
    this.createDate = DateTime.now();
    this.weatherCode = weatherCode;
    this.content = content;
    this.title = title;
  }

  public String getContent() {
    return content;
  }

  public String getTitle() {
    return title;
  }

  public int getYear() {
    return createDate.year();
  }

  public String getYearDay() {
    return createDate.toDateStr();
  }

  public int getMonth() {
    return createDate.month();
  }

  public int getMonthDay() {
    return createDate.dayOfMonth();
  }

  public String getWeekDay() {
    return DateConstants.weekdays[createDate.dayOfWeek() - 1];
  }

  public String getTime() {
    return createDate.toTimeStr();
  }

  public String getDateStr() {
    return createDate.toString(DatePattern.NORM_DATETIME_PATTERN);
  }

  @Override
  public String toString() {
    return "DiaryNote{" +
      "id=" + id +
      ", createDate=" + createDate.toString() +
      ", weatherCode=" + weatherCode +
      ", title='" + title + '\'' +
      ", content='" + content + '\'' +
      '}';
  }
}


